What is core-util-is?
The core-util-is package provides utility functions for checking the types of JavaScript values, similar to the 'util.is*' functions that were available in Node.js but have since been deprecated. It allows developers to accurately determine the type of a variable, which can be particularly useful when dealing with APIs that may return data of various types or when validating input.
What are core-util-is's main functionalities?
isArray
Checks if a value is an Array.
var is = require('core-util-is');
var result = is.isArray([1, 2, 3]); // result will be true
isBoolean
Checks if a value is a Boolean.
var is = require('core-util-is');
var result = is.isBoolean(false); // result will be true
isNull
Checks if a value is null.
var is = require('core-util-is');
var result = is.isNull(null); // result will be true
isNullOrUndefined
Checks if a value is null or undefined.
var is = require('core-util-is');
var result = is.isNullOrUndefined(null); // result will be true
isNumber
Checks if a value is a Number.
var is = require('core-util-is');
var result = is.isNumber(42); // result will be true
isString
Checks if a value is a String.
var is = require('core-util-is');
var result = is.isString('node'); // result will be true
isSymbol
Checks if a value is a Symbol.
var is = require('core-util-is');
var result = is.isSymbol(Symbol('foo')); // result will be true
isUndefined
Checks if a value is undefined.
var is = require('core-util-is');
var result = is.isUndefined(undefined); // result will be true
isObject
Checks if a value is an Object.
var is = require('core-util-is');
var result = is.isObject({}); // result will be true
isFunction
Checks if a value is a Function.
var is = require('core-util-is');
var result = is.isFunction(function() {}); // result will be true
isPrimitive
Checks if a value is a primitive (not an Object).
var is = require('core-util-is');
var result = is.isPrimitive('string'); // result will be true
isBuffer
Checks if a value is a Buffer object.
var is = require('core-util-is');
var result = is.isBuffer(Buffer.from('node')); // result will be true
Other packages similar to core-util-is
lodash
Lodash is a comprehensive utility library that provides a wide range of functions for manipulating and checking data types, among many other utilities. It offers similar type-checking functions like _.isArray, _.isBoolean, etc., and is more extensive than core-util-is.
kind-of
Kind-of is a simple utility for checking the type of a value. It is similar to core-util-is but provides a single function that returns the type as a string, rather than multiple functions for each type.
is
The 'is' package offers a set of type check functions for JavaScript, which can be used both in Node.js and in the browser. It is similar to core-util-is but also includes additional checks for types like 'is.integer' or 'is.float'.